package basedto

import (
	"gitee.com/ichub/goconfig/common/base/baseiface"
	"gitee.com/ichub/goconfig/common/base/baseutils"
	"gitee.com/ichub/goconfig/common/base/baseutils/stringutils"
)

type BaseEntity struct {
	Proxy    func() *BaseProxy             `json:"-"`
	Bindings map[string]baseiface.LoadBean `json:"-"`
	RootDir  string                        `json:"-"`
}

func NewBaseEntity() *BaseEntity {
	var entity = &BaseEntity{
		Bindings: map[string]baseiface.LoadBean{},
	}

	entity.InitProxy(entity)
	return entity
}

func (this *BaseEntity) InitProxy(some any) {
	this.Proxy = func() *BaseProxy {

		return NewBaseProxy(some)
	}

}

func (this *BaseEntity) String() string {

	return this.Proxy().String()
}

func (this *BaseEntity) ToString() string {

	return this.Proxy().ToString()
}

func (this *BaseEntity) Log() {

	this.Proxy().Log()

}
func (this *BaseEntity) ContainsType(name string) bool {
	return this.Proxy().ContainsType(name)
}
func (this *BaseEntity) Clone() interface{} {
	return this.Proxy().Clone()
}

func (this *BaseEntity) ValueOf(that any) {
	this.Proxy().ValueOf(that)
}

func (this *BaseEntity) FromJsonAny(body []byte) interface{} {
	return this.Proxy().FromJson(body)

}
func (this *BaseEntity) ToJson() string {
	return this.Proxy().ToJson()

}

func (this *BaseEntity) ToJsonBytes() []byte {
	return this.Proxy().ToJsonBytes()
}
func (this *BaseEntity) ToPrettyString() string {
	if this.Proxy() == nil {
		return "{}"
	}
	return this.Proxy().ToPrettyString()
}

func (this *BaseEntity) Id2Str(id int64) string {
	return baseutils.Any2Str(id)
}

func (this *BaseEntity) ValueFrom(from any) {
	this.Proxy().ValueFrom(from)

}

func (this *BaseEntity) Str2Int(from string) int {

	return stringutils.Str2Int(from)
}
func (this *BaseEntity) CopyWithOption(from any) {
	this.Proxy().CopyWithOption(from)

}
func (this *BaseEntity) Bind() {
	//this.BindUp()

}
func (this *BaseEntity) BindUp(key string, load baseiface.LoadBean) {
	if this.Bindings == nil {
		this.Bindings = map[string]baseiface.LoadBean{}
	}
	//key = strings.ToLower(key)
	this.Bindings[key] = load

}
func (this *BaseEntity) FindBinding(key string) baseiface.LoadBean {

	return this.Bindings[key]

}

func (this *BaseEntity) Single() bool {
	return false //this.Proxy().Single()
}
func (this *BaseEntity) Autoload() bool {
	return false //this.Proxy().Autoload()

}
func (this *BaseEntity) AutoInject() bool {
	return false //this.Proxy().AutoInject()

}
func (this *BaseEntity) Init() {
	this.Proxy().Init()
}
func (this *BaseEntity) Shutdown() {
	this.Proxy().Shutdown()
}
